import { _decorator, Button, Component, director, TextAsset ,Node, Scene} from 'cc';
import { AbNames, GamePkg } from './Config/ResConfig';
import { WSConnectedEvent } from '../../Framework/Scripts/Managers/Net/NetCfg';
import { Platform } from '../../Framework/Scripts/Platform/PlatformWX';
import { UIMgr, UIType } from '../../Framework/Scripts/Managers/UIMgr';
import { ResManager } from '../../Framework/Scripts/Managers/ResManager';
import { ExcelMgr } from '../../Framework/Scripts/Managers/ExcelMgr';
import { TestData } from './Data/TestData';
import { SceneMgr } from '../../Framework/Scripts/Managers/SceneMgr';
const { ccclass, property } = _decorator;

@ccclass('GM')
export class GM extends Component {
    @property({type:Node})
    root:Node;

    start() {

    }

    //回调蛋疼
    private onBtnClick(btn: Button,key: any){
        console.log('========onBtnClick==========',key);

        switch (key) {
            case 'Button':
                this.onBtnShowAndHide();
                break;
            case 'btn1':
                this.onNetConnect();
                break;
            case 'btn2':
                this.onWxShareApp();
                break;
            case 'btn3':
                this.onWxShareImg();
                break;
            case 'btn4':
                this.onLogin();
                break;
            case 'btn5':
                this.onTest();
                break;
            case 'btn6':
                this.onOtherAnswer(true);
                break;
            case 'btn7':
                this.onOtherAnswer(false);
                break;
            case 'btn8':
                this.onNextTopic();
                break;
            case 'btn9':
                this.onFriendJoin();
                break;
            case 'btn10':
                this.onFriendJoinNotify();
                break;
            case 'btn11':
                this.onTopicAnswerEnd();
                break;
            case 'btn12':
                this.loadingToHall();
                break;
            case 'btn13':
                this.hallToGame1();
                break;
            case 'btn14':
                this.gameToHall();
                break;
            default:
                break;
        }

    }

    private onBtnShowAndHide(){
        this.root.active = !this.root.active;
    }

    private onNetConnect(){
        director.emit(WSConnectedEvent, "");
    }

    //微信分享游戏
    private onWxShareApp(){
        Platform.inst.shareFriend();
    }

      //微信当前游戏截屏
    private onWxShareImg(){
        Platform.inst.shareFriendImg();
    }

    //游客登录
    private onLogin(){
    }

    // 测试
    private onTest(){
        UIMgr.inst.ShowUIView(AbNames.GameHall,'Prefabs/NewPlayer',2);
        ResManager.inst.loadDirAssetboundle([GamePkg],(now: number, total: number)=>{},()=>{
            console.log("======loadAb Hall End========")
            let txt = ResManager.inst.getAsset(AbNames.GamePlay,'Excle/DT',TextAsset) as TextAsset;
            ExcelMgr.inst.AddTable('DT',txt.text);

            let res = ExcelMgr.inst.QueryOne('DT',1001);
            console.log('=======res==========',res)
        })

        // TestData.inst.ThemeMatchGameEndBroadcast();
    }

    //他人答题
    private onOtherAnswer(isDui: boolean){
        TestData.inst.onThemeMatchGameAnswerResTest2(isDui);
    }

    //主题赛下一题
    private onNextTopic(){
        TestData.inst.ThemeMatchGameNextBroadcastTest();
    }

    //好友加入
    private onFriendJoin(){
        TestData.inst.onFriendJoinBroadcast();
    }

    //用户被邀请通知
    private onFriendJoinNotify(){
        TestData.inst.onFriendJoinNotify();
    }

    //当前题目答结束
    private onTopicAnswerEnd(){
        TestData.inst.GameAnswerEndBroadcast();
    }

    //加载到大厅
    private loadingToHall(){
        SceneMgr.inst.LoadingToHall();
    }

    //大厅到游戏
    private hallToGame1(){
        // ResManager.inst.loadDirAssetboundle([GamesPkg],(now: number, total: number)=>{
        // },()=>{
        //     console.log("======loadAb Hall End========")
        //     setTimeout(()=>{
        //         //打开大厅
        //         UIMgr.inst.ShowUIView(AbNames.GamePlay,'Prefabs/Node',UIType.Full);
        //         ResManager.inst.ReleaseAllAssetInBundle(AbNames.GameHall);
        //     },500)
        // })

        // ResManager.inst.loadDirAssetboundle([GamesPkg],(now: number, total: number)=>{},()=>{
        //     console.log("======loadAb Games End========")
        //     setTimeout(()=>{
        //         this.showGame();

        //         setTimeout(()=>{
        //             // ResManager.inst.ReleaseAllAssetInBundle(AbNames.GameHall);
        //         },1000*3)
               
        //     },500)
        // })
    }

    //游戏到大厅
    private gameToHall(){
        
    }
}